package com.sky.city.util;

import android.content.Context;
import android.widget.ImageView;

import androidx.annotation.DrawableRes;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.sky.city.R;

public class ImageUtils {

    /**
     * 加载网络图片 设置磁盘缓存(设置内存缓存) 头像加载
     */
    public static void loadAvatarImgMemory(Context mContext, String path, ImageView imageview) {
        RequestOptions options = new RequestOptions()
            .skipMemoryCache(false).diskCacheStrategy(DiskCacheStrategy.ALL)
            .placeholder(R.mipmap.icon_headdefault).error(R.mipmap.icon_headdefault);
        Glide.with(mContext)
            .load(path)
            .apply(options)
            .into(imageview);
    }





    /**
     * 自定义默认加载
     */
    public static void loadImgMemory(Context mContext, String path, ImageView imageview,
        @DrawableRes int defaultResId) {
        RequestOptions options = new RequestOptions()
            .skipMemoryCache(false).diskCacheStrategy(DiskCacheStrategy.ALL)
            .placeholder(defaultResId).error(defaultResId);
        Glide.with(mContext)
            .load(path)
            .apply(options)
            .into(imageview);
    }

    public static void loadImagePicMemory(Context mContext, String path, ImageView imageview) {
        RequestOptions options = new RequestOptions()
            .skipMemoryCache(false).diskCacheStrategy(DiskCacheStrategy.ALL)
            .placeholder(R.drawable.no_banner).error(R.drawable.no_banner);
        Glide.with(mContext)
            .load(path)
            .apply(options)
            .into(imageview);
    }

    public static void loadImageLoginUserMemory(Context mContext, String path,
        ImageView imageview) {
        RequestOptions options = new RequestOptions()
            .skipMemoryCache(false).diskCacheStrategy(DiskCacheStrategy.ALL)
            .placeholder(R.drawable.no_banner).error(R.drawable.no_banner);
        Glide.with(mContext)
            .load(path)
            .apply(options)
            .into(imageview);
    }

    public static void loadImageLoginUserNewMemory(Context mContext, String path,
        ImageView imageview) {
        RequestOptions options = new RequestOptions()
            .skipMemoryCache(false).diskCacheStrategy(DiskCacheStrategy.ALL)
            .placeholder(R.drawable.no_banner).error(R.drawable.no_banner);
        Glide.with(mContext)
            .load(path)
            .apply(options)
            .into(imageview);
    }

    public static void loadImageDoctorFengCai(Context mContext, String path, ImageView imageview) {
        RequestOptions options = new RequestOptions()
            .skipMemoryCache(false).diskCacheStrategy(DiskCacheStrategy.ALL)
            .placeholder(R.drawable.no_banner).error(R.drawable.no_banner);
        Glide.with(mContext)
            .load(path)
            .apply(options)
            .into(imageview);
    }

    public static void loadVideoDoctorFengCai(Context mContext, String path, ImageView imageview) {
        RequestOptions options = new RequestOptions()
            .skipMemoryCache(false).diskCacheStrategy(DiskCacheStrategy.ALL)
            .placeholder(R.drawable.no_banner).error(R.drawable.no_banner);
        Glide.with(mContext)
            .load(path)
            .apply(options)
            .into(imageview);
    }

    public static void loadImageLoginDoctorMemory(Context mContext, String path,
        ImageView imageview) {
        RequestOptions options = new RequestOptions()
            .skipMemoryCache(false).diskCacheStrategy(DiskCacheStrategy.ALL)
            .placeholder(R.drawable.no_banner).error(R.drawable.no_banner);
        Glide.with(mContext)
            .load(path)
            .apply(options)
            .into(imageview);
    }

    /**
     * 加载本地图片,不需要用缓存机制
     */
    public static void loadLocalImage(Context mContext, String uri, ImageView imageView) {
        RequestOptions options = new RequestOptions()
            .placeholder(R.drawable.no_banner).error(R.drawable.no_banner);
        Glide.with(mContext)
            .load(uri)
            .apply(options)
            .into(imageView);
    }

    /**
     * 加载本地gif
     */
    public static void loadLocalGifImage(Context context, String url, ImageView imageView) {
        RequestOptions options = new RequestOptions()
            .skipMemoryCache(false).diskCacheStrategy(DiskCacheStrategy.ALL);
        Glide.with(context).asGif().load(url).apply(options).into(imageView);
    }

}
